//
//  MainHomePageTabBarView.swift
//  FrameProduct
//
//  Created by delegate on 2025/10/20.
//

import UIKit

class MainHomePageTabBarView: UIView {
    var hotTabItemTapFunctionBlock: (() -> Void)?
    var switchTabItemTapFunctionBlock: (() -> Void)?
    var buyTabItemTapFunctionBlock: (() -> Void)?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI() {
        addSubviews(tabBgImageView)
        tabBgImageView.addSubviews(holdTabItem, switchTabItem, buyTabItem)
        tabBgImageView.snp.makeConstraints { make in
            make.bottom.top.left.right.equalToSuperview()
        }
        holdTabItem.snp.makeConstraints { make in
            make.left.equalTo(40)
            make.bottom.equalTo(0)
        }
        switchTabItem.snp.makeConstraints { make in
            make.left.equalTo(holdTabItem.snp.right).offset(40)
            make.bottom.equalTo(0)
            make.width.equalTo(holdTabItem.snp.width)
        }
        buyTabItem.snp.makeConstraints { make in
            make.left.equalTo(switchTabItem.snp.right).offset(40)
            make.bottom.equalTo(0)
            make.width.equalTo(switchTabItem.snp.width)
            make.right.equalTo(-40)
        }
    }
    //=================================================================
    //                           事件处理
    //=================================================================
    // MARK: - 事件处理
    @objc private func hotTabItemTapAction() {
        hotTabItemTapFunctionBlock?()
    }
    @objc private func switchTabItemTapAction() {
        switchTabItemTapFunctionBlock?()
    }
    @objc private func buyTabItemTapAction() {
        buyTabItemTapFunctionBlock?()
    }
    //=================================================================
    //                            lazy
    //=================================================================
    // MARK: - lazy
    private lazy var tabBgImageView: UIImageView = {
        let imageView = UIImageView(frame: .zero)
        imageView.image = UIImage(named: "tabbar_bg_img")
        imageView.isUserInteractionEnabled = true
        return imageView
    }()
    private lazy var holdTabItem: MainHomePageTabBarSubView = {
        let item = MainHomePageTabBarSubView()
        item.setIconImageView(icon: "home_hold_img", title: "热门应用")
        let tap = UITapGestureRecognizer(target: self, action: #selector(hotTabItemTapAction))
        item.addGestureRecognizer(tap)
        return item
    }()
    private lazy var switchTabItem: MainHomePageTabBarSubView = {
        let item = MainHomePageTabBarSubView()
        item.setIconImageView(icon: "tabar_center_btn_icon", title: "切换模式", titleTopOffset: 14)
        item.setTitle(color: .lxs.hex("#FFFFFF"))
        let tap = UITapGestureRecognizer(target: self, action: #selector(switchTabItemTapAction))
        item.addGestureRecognizer(tap)
        return item
    }()
    private lazy var buyTabItem: MainHomePageTabBarSubView = {
        let item = MainHomePageTabBarSubView()
        item.setIconImageView(icon: "home_shoping_img", title: "购买")
        let tap = UITapGestureRecognizer(target: self, action: #selector(buyTabItemTapAction))
        item.addGestureRecognizer(tap)
        return item
    }()
}
